package org.jsola.hr.helper;

import org.jsola.hr.dto.EmpContactsUrgentAddDTO;
import org.jsola.hr.dto.EmpContactsUrgentUpdateDTO;
import org.jsola.hr.entity.EmpContactsUrgentDO;
import org.jsola.hr.query.EmpContactsUrgentQuery;
import org.jsola.hr.service.IEmpContactsUrgentService;
import org.jsola.hr.vo.EmpContactsUrgentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工紧急联系人
 *
 * @author zhr
 */
@Component
public class EmpContactsUrgentTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpContactsUrgentService empContactsUrgentService;

    /**
     * 生成add测试数据
     * @return EmpContactsUrgentAddDTO
     */
    public EmpContactsUrgentAddDTO getEmpContactsUrgentAddDTO(){
        EmpContactsUrgentAddDTO empContactsUrgentAddDTO = new EmpContactsUrgentAddDTO();
        empContactsUrgentAddDTO.setEmpId(getRandomValue("varchar",32));
        empContactsUrgentAddDTO.setName(getRandomValue("varchar",255));
        empContactsUrgentAddDTO.setRelation(getRandomValue("varchar",255));
        empContactsUrgentAddDTO.setPhone(getRandomValue("varchar",11));
        empContactsUrgentAddDTO.setAddress(getRandomValue("varchar",255));
        empContactsUrgentAddDTO.setCompanyId(getRandomValue("varchar",32));
        return empContactsUrgentAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpContactsUrgentUpdateDTO
     */
    public EmpContactsUrgentUpdateDTO getEmpContactsUrgentUpdateDTO(EmpContactsUrgentVO empContactsUrgentVO){
        return empContactsUrgentService.selectDOById(empContactsUrgentVO.getId(), SITE_ID).to(EmpContactsUrgentUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpContactsUrgentQuery
     */
    public EmpContactsUrgentQuery getEmpContactsUrgentQuery() {
        EmpContactsUrgentQuery empContactsUrgentQuery = new EmpContactsUrgentQuery();
        List<EmpContactsUrgentDO> empContactsUrgentDOList = empContactsUrgentService.list(new EmpContactsUrgentDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empContactsUrgentDOList)) {
            EmpContactsUrgentDO empContactsUrgentDO = empContactsUrgentDOList.get(0);
            empContactsUrgentQuery = empContactsUrgentDO.to(EmpContactsUrgentQuery.class);
        }
        return empContactsUrgentQuery;
    }

    /**
     * 保存示例
     * @return EmpContactsUrgentVO
     */
    public EmpContactsUrgentVO saveEmpContactsUrgentExample(){
        EmpContactsUrgentAddDTO addDTO = this.getEmpContactsUrgentAddDTO();
        EmpContactsUrgentVO empContactsUrgentVO = empContactsUrgentService.save(addDTO,buildTokenUser());
        return empContactsUrgentVO;
    }


}

